import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

class PersonSortable2{
	private String name;
	private int age;
	public PersonSortable2(String name,int age){
		this.name=name;
		this.age=age;
	}
	public String getName() {
		return name;
	}
	public int getAge() {
		return age;
	}
	@Override
	public String toString() {
		return name+"-"+age;
	}
}
class NameComparator implements Comparator<PersonSortable2>{
    @Override
	public int compare(PersonSortable2 o1, PersonSortable2 o2) {
		return new String (o1.getName()).compareTo(o2.getName());
	}
}
class AgeComparator implements Comparator<PersonSortable2>{
	@Override
	public int compare(PersonSortable2 o1, PersonSortable2 o2) {
		return o1.getAge()-o2.getAge();
	}
    }
public class Main{
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		PersonSortable2[] ps=new PersonSortable2[n];
		//NameComparator[] name=new NameComparator[n];
		//AgeComparator[] age=new AgeComparator[n];
		for(int i=0;i<n;i++){
			ps[i]=new PersonSortable2(in.next(),in.nextInt());
			//name[i]=new NameComparator();
			//name[i].compare(o1, o2);
		}
		
		System.out.println("NameComparator:sort");
		Arrays.sort(ps,new NameComparator());
		for(PersonSortable2 p:ps){
		System.out.println(p);
		}
		System.out.println("AgeComparator:sort");
		Arrays.sort(ps,new AgeComparator());
		for(PersonSortable2 p:ps){
		System.out.println(p);
		}
		System.out.println(Arrays.toString(NameComparator.class.getInterfaces()));
		System.out.println(Arrays.toString(AgeComparator.class.getInterfaces()));
	}
}
